package com.cuit.bysj.action;

import net.sf.json.JSONObject;

import com.cuit.bysj.entities.Student;
import com.cuit.bysj.entities.User;
import com.cuit.bysj.service.StuService;
import com.cuit.bysj.utils.JsonHelper;
import com.cuit.bysj.utils.Result;
import com.opensymphony.xwork2.ActionSupport;

//ѧ������Action
public class StuManageAction extends ActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	public String result;
	private StuService stuService;
	private String id;
	private String sex;
	private String banji;
	private String age;
	private String major;

	public String getSex() {
		return sex;
	}

	public void setSex(String sex) {
		this.sex = sex;
	}

	public String getBanji() {
		return banji;
	}

	public void setBanji(String banji) {
		this.banji = banji;
	}

	public String getAge() {
		return age;
	}

	public void setAge(String age) {
		this.age = age;
	}

	public String getMajor() {
		return major;
	}

	public void setMajor(String major) {
		this.major = major;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public StuService getStuService() {
		return stuService;
	}

	public void setstuService(StuService stuService) {
		this.stuService = stuService;
	}

	public void setResult(String result) {
		this.result = result;
	}

	/*
	 * ����ѧ���б���
	 */
	public String openpage() {
		Result<User> Userresult = new Result<User>();
		Userresult.setSuccess(true);
		Userresult.setUrl("StulistPage");

		result = JSONObject.fromObject(Userresult).toString();

		return "json";
	}

	public String loadStulist() {
		Result<Student> Sturesult = new Result<Student>();

		Sturesult.setItems(stuService.stulist());

		result = JsonHelper.getJsonHelper().format(Sturesult);

		return "json";
	}

	public String findStu() {
		Result<Student> Sturesult = new Result<Student>();

		Sturesult.setItem(stuService.findStu(Integer.parseInt(id)));

		result = JsonHelper.getJsonHelper().format(Sturesult);

		return "json";
	}

	public String updateStu() {
		Result<Student> Sturesult = new Result<Student>();

		Student stu = stuService.findStu(Integer.parseInt(id));
		stu.setBanji(banji);
		stu.setAge(age);
		stu.setMajor(major);
		stu.setSex(sex);
		stuService.updateStu(stu);
		Sturesult.setMsg("修改成功");

		result = JsonHelper.getJsonHelper().format(Sturesult);

		return "json";
	}
}
